package weiyao.xinxidasai.mapper;

import org.apache.ibatis.jdbc.SQL;

public class KeySqlProvider {


    public String selectFoldersWithVersionByUserId(Long userId) {
        return new SQL() {{
            SELECT("v.version_id", "v.version_no", "f.folder_path");
            FROM("files_folder f");
            INNER_JOIN("version v ON f.version_id = v.version_id");
            WHERE("f.user_id = #{userId}");
        }}.toString();
    }


            public String findAncestorFoldersSql() {
                return "WITH RECURSIVE folder_tree AS ("
                        + "SELECT folder_id, parent_id, name "
                        + "FROM files_folder "
                        + "WHERE folder_id = #{folderId} "
                        + "UNION ALL "
                        + "SELECT ff.folder_id, ff.parent_id, ff.name "
                        + "FROM files_folder ff "
                        + "INNER JOIN folder_tree ft ON ff.folder_id = ft.parent_id) "
                        + "SELECT * FROM folder_tree";
            }


}